package com.example.myapplicationndk.itemtouch;

import android.os.Bundle;

import com.example.myapplicationndk.R;
import com.example.myapplicationndk.databinding.ActivityTestBinding;
import com.example.myapplicationndk.utils.GenerateString;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class TestActivity extends AppCompatActivity {

    private ActivityTestBinding mTestBinding;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);


        RecyclerView recycle = findViewById(R.id.mRecyclerView);

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        recycle.setLayoutManager(linearLayoutManager);
        List<String> list = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            list.add(GenerateString.getRandomString(new Random().nextInt(10 + 5)));
        }


        recycle.setLayoutManager(new LinearLayoutManager(this));
        recycle.setHasFixedSize(true);
        MyAdapter adapter = new MyAdapter(this, list);
        recycle.setAdapter(adapter);

//        RecyclerView与ItemTouchHelper关联
        ItemTouchHelper.Callback callback = new MyItemTouchHelperCallback(adapter);
        ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
        itemTouchHelper.attachToRecyclerView(recycle);

    }


}

